package com.example.springbootjpaintegrat.conversion;

import com.example.springbootjpaintegrat.model.User;
import com.openapi.open.controller.model.OpenCreateUserRequest;
import com.openapi.open.controller.model.OpenUpateUserRequest;
import com.openapi.open.controller.model.OpenUser;
import org.springframework.stereotype.Component;

/**
 * @Author qrn
 * @Date 2022/7/29 下午10:28
 * @Version 1.0
 * @blog https://blog.csdn.net/qq_41971087
 */
@Component
public class UserConversion {

    public User toUser(OpenCreateUserRequest openCreateUserRequest){
       return new User().setName(openCreateUserRequest.getName())
                .setRemark(openCreateUserRequest.getRemark());
    }

    public User toUser(OpenUpateUserRequest openUpateUserRequest){
        return new User().setName(openUpateUserRequest.getName())
                .setRemark(openUpateUserRequest.getRemark());
    }

    public OpenUser toControllerOpenUser(User user){
        if(user == null) return  null;
        return new OpenUser().id(String.valueOf(user.getId()))
                .name(user.getName())
                .remark(user.getRemark());

    }
}
